package edu.hawaii.halealohacli.jcev.command;

import org.wattdepot.client.WattDepotClient;
import edu.hawaii.halealohacli.jcev.processor.ExitException;

/**
 * The quit command which exits the command line interface.
 * @author Christopher Foo
 *
 */
public class Quit implements Command {

  @Override
  /**
   * Verifies the arguments and exits the command line processor if invoked correctly.
   * @param args Space delimited string of arguments (i.e. "arg1 arg2 arg3").
   * @param client The WattDepot client that will be performing the queries.
   * @throws Exception If an exception was thrown by the command (i.e. bad arguments)
   * or any of its function calls.
   */
  public void execute(String args, WattDepotClient client) throws Exception {
    
    //If arguments are good
    if (verifyArguments(args)) {
      throw new ExitException("Quitting...");
    }
    else {
      throw new Exception("Bad input: More than 0 arguments." + " Correct Syntax: help");
    }
  }

  @Override
  /**
   * Returns the string to be printed by the help command.
   * Format:
   * "command-name [args1] [args2] .... \nDescription"
   * @return The string to be printed by the help command.
   */
  public String getHelpString() {
    return "quit\n" +
           "Terminates execution.";
  }
  
  /**
   * Checks that the arguments are valid.
   * @param args The string of arguments.
   * @return If the arguments are valid.
   */
  public boolean verifyArguments(String args) {
    return "".equals(args.trim());
  }
}
